﻿
YUI.add('seleccionar-docente-list-view', function (Y) {
    Y.SeleccionarDocentesView = Y.Base.create('SeleccionarDocentesView', Y.View, [], {
        loadTemplate: function () {
            if (this.template == '') {
                var that = this,
                request = Y.io('/ExcellentProject/scripts/views/seguridades/docentes/templates/seleccionardocente.html', {
                    on: {
                        complete: function (id, response) {
                            that.templateIsCharged = true;
                            that.template = response.responseText;
                            try {
                                $('#table_id').parent().replaceWith('');
                            }
                            catch (err) {
                                console.log(err);
                            }
                            that.render();
                        },
                        failure: function (id, response) {
                            alert(response, 'Error al cargar la lista de Docentes')
                        }

                    }
                })
            }
        },
        render: function () {
            this.loadTemplate();
            if (this.templateIsCharged) {
                this.get('container').setHTML(this.template);
                var list = this.get('modelList');
                var model = this.get('model');
                var table = $('#table_id').DataTable({
                    "paging": true,
                    retrieve: true,
                    data: list._items,
                    columns: [
                        { data: '_state.data.Id.lazy.value' },
                        { data: '_state.data.Nombre.lazy.value' },
                        { data: '_state.data.Apellido.lazy.value' },
                        { data: '_state.data.Direccion.lazy.value' },
                        { data: '_state.data.Telefono.lazy.value' },
                        { data: '_state.data.Correo.lazy.value' },
                        { data: '_state.data.Id.lazy.value' }
                    ]
                });
                table.draw();
            }
        }
    })
}, '0.0.0.1', {
    requires: ['view', 'docente-model-list', 'docente-model', 'io', 'handlebars']
})